<template>
	<view style="padding: 30px;">
		<u--form :model="login_info">
			<u-form-item label="用户名" label-width="80px" borderBottom><u--input v-model="login_info.username" /></u-form-item>
			<u-form-item label="密码" label-width="80px" borderBottom><u--input v-model="login_info.password" /></u-form-item>
			<u-form-item label="openid" label-width="80px" borderBottom><u--input v-model="login_info.openid" placeholder="通常可不填" /></u-form-item>
		</u--form>
		<u-button @click="post()" color="rgb(0, 122, 153)" plain="true" size="large">登录</u-button>
	</view>
</template>

<script>
	import sha256 from "@/static/sha256.js"
	export default {
		data() {
			return {
				login_info: {
					username: "",
					password: "",
					openid: null,
				}
			}
		},
		methods: {
			post() {
				
				uni.request({
					url: getApp().globalData.base_url + "/login_with_pwd",
					method: "POST",
					data: {
						username: this.login_info.username,
						password: sha256(this.login_info.password),
						openid: this.login_info.openid
					}
				})
				.then(data => {
					let token = data.data.token
					getApp().globalData.access_token = token
					uni.setStorageSync("access_token", token)
					getApp().globalData.refreshLoginStatus()
					uni.switchTab({
						url: "/pages/index/index"
					})
				})
				.catch(err => {
					console.log(err)
				})
			}
		}
	}
</script>

<style>
	
</style>
